// XML support, wrapping tinyxml and tinyxpath
// Copyright 2006 (C) Ralph Thomas

#include <util/xml.h>
#include <xpath_static.h>
#include <stdexcept>
#include <sstream>

namespace util {
	xml_doc_t parse_xml( const std::string& xml ) {
		xml_doc_t doc( new TiXmlDocument() );
		doc->Parse( xml.c_str() );
		if( doc->Error() ) { 
			std::stringstream ss;
			ss << doc->ErrorDesc() << " at line "
				<< doc->ErrorRow() << " col "
				<< doc->ErrorCol();
			throw std::runtime_error( ss.str() );
		}
		return doc;
	}
	std::string xpath_eval_string( TiXmlElement* n, const std::string& xpath ) {
		//
		// XXX: Need error checking on this!
		//
		return TinyXPath::S_xpath_string( n, xpath.c_str() );
	}
}
